package com.hjq.controller;

import com.hjq.pojo.Emp;
import com.hjq.pojo.LoginInfo;
import com.hjq.pojo.Result;
import com.hjq.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录请求
 */
@Slf4j
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    EmpService empService;
    /**
     * 登录请求
     * @param emp 用户名和密码
     * @return 登录信息
     */
    @PostMapping
    public Result login(@RequestBody Emp emp){
        log.info("员工登录：{}",emp);
        LoginInfo info = empService.login(emp);
        if(info!=null)
            return Result.success(info);
        return Result.error("用户名或密码错误");

    }

}
